/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is
*   Nick Kreeger
* Portions created by the Initial Developer are Copyright (C) 2006-2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*   Nick Kreeger <nick.kreeger@park.edu>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */

#import <Cocoa/Cocoa.h>

@class MessagesDataSource;
@class MailboxItem;
@class MailWindowController;
@class MessageHeader;

/**
 * This protocol insures consitency between the service and 
 * the storage class.
 */
@protocol MessageListDataProvider

-(void)clearMessages;
-(unsigned int)messageCount;
-(void)sortUsingSelector:(SEL)aSelector;
-(BOOL)isSortedDescending;
-(unsigned int)messageIndexForMessageId:(NSString*)aMessageID;

@end

/**
 * This protocol allows any object interested
 * in the copy status of messages to be notified.
 */
@protocol MessageCopyListener

-(void)onStartCopy;
-(void)onStopCopy;

@end

/** 
 * This class provides a layer between the UI and the actual 
 * message list data source. Functions such as message URI 
 * loading, setting message header flags, and other data related
 * features are handled here.
 */
@interface MessageListDataSource : NSObject <MessageListDataProvider, MessageCopyListener>
{
  MessagesDataSource*   mMessagesDataSource;
  MailWindowController* mMailWindowController;  // weak ref
  MailboxItem*          mCurMailboxItem;        // weak ref
  
  NSImage* mFlagImage;
  NSImage* mUnreadImage;
  NSImage* mBlankImage;
  BOOL     mIsUpdatingImapFolder;
  int      mSelectedMessageIndex;
  int      mNextSelectionIndex;  // Stores the next selection index when waiting for 
                                 // an event like deletion or copy.
}

-(id)initWithMailWindowController:(MailWindowController*)aMailWindowController;

/**
 * Notification method to inform the service when n number of messages
 * have been selected in a list view. 
 * 
 * This method will also initiate the loading of a message, based upon
 * the input.
 * @param aIndexSet The NSIndexSet instance of the selected messages.
 */
-(void)didSelectMessageRows:(NSIndexSet*)aIndexSet;

-(void)reloadCurrentMessage;

/**
 * Load the messages for the passed in mailbox name.
 * @param inMailboxItem The mailbox to load.
 * @param inIsUpdating If the message list is updating.
 */
-(void)loadMessagesForMailbox:(MailboxItem*)inMailboxItem isUpdating:(BOOL)inIsUpdating;

-(unsigned int)unreadMessageCount;
-(unsigned int)newMessageCount;

/**
 * Find out if the current mailbox folder is an IMAP folder.
 * @return If the current mailbox folder is an IMAP folder.
 */
-(BOOL)isCurrentMailboxIMAP;

/**
 * Set the read state of a list of messages determined by their index.
 * @param inMessagesIndexes The indexes of the messages to mark.
 * @param inIsRead The read state of each message header.
 */
-(void)markMessageIndexes:(NSIndexSet*)inMessagesIndexes areRead:(BOOL)inIsRead;

/**
 * Set the flagged state of a list of messages determined by their index.
 * @param inMessagesIndexes The indexes of the messages to mark.
 * @param inIsFlagged The flagged state of each message header.
 */
-(void)markMessageIndexes:(NSIndexSet*)inMessagesIndexes areFlagged:(BOOL)inIsFlagged;

-(void)markAllMessagesRead;

/**
 * Delete a message list. 
 *  - Messages stored on IMAP, the message is deleted permanently.
 *  - Messages stored via a POP3 account are moved to the trash folder.
 *  - Messages stored in a trash folder are deleted permanently.
 * @param inMsgIndexSet The message index list to delete.
 */
-(void)deleteMessages:(NSIndexSet*)inMsgIndexSet;

/*
 XXX kreeger:
 I don't think comparing message ID's is the quickest solution
 */

/**
 * Get the message ID at a a specified index. Note that this 
 * is *not* a URI, but a unique numerical ID given to a message.
 * @param inIndex The index of hte message to look up.
 * @return The message's ID, or nil if one does not exist.
 *         Return value is autoreleased.
 */ 
-(NSString*)messageIdForMessageAtIndex:(int)inIndex;

/**
 * Get the index of a message given a message ID. Note that this
 * is *not* a URI, but a unique numerical ID give to a message.
 * @param aMessageID The message ID.
 * @return The index of the message with the given message ID.
 */
-(unsigned int)messageIndexForMessageId:(NSString*)aMessageID;

/**
 * Get a URI for a message at a specified index.
 * @param inIndex The index of the message to look up.
 * @return The message's URI, or nil if one does not exist.
 *         Return value is autoreleased.
 */
-(NSString*)generateUriForMessageAtIndex:(int)inIndex;


/**
 * Get a URI for a message with the given |MessageHeader| object.
 * @param aMessageHeader The message header to lookup
 * @return The URI of the message header or nil if one does not exist.
 */
-(NSString*)generateUriForMessageHeader:(MessageHeader*)aMessageHeader;

/**
 * Get a message header object at the specified index.
 * @param inIndex The index of the message to look up.
 * @return The |MessageHeader| object, or nil if one does not exist.
 */
-(MessageHeader*)messageHeaderAtIndex:(int)inIndex;

@end
